from jiekou.port_job.mall.interface.Interface import Memberlnterface
from jiekou.port_job.mall.utils.sendmethod import SendMethod


class OrderInterface:
    def __init__(self, url, headers):
        self.url = url
        self.headers = headers

    def confirm_order(self, cart_id):   #确认订单
        method = 'post'
        url = self.url + '/order/generateConfirmOrder'

        return SendMethod.send_method(method=method, url=url, json=[cart_id], headers=self.headers)



    def generate_order(self, cart_id):   #生成订单
        method = 'post'
        url = self.url + '/order/generateOrder'
        payload = {
            "cartIds": [
                cart_id
            ],
            "memberReceiveAddressId": 2464,  # 收货地址id
            "payType": 2,  # 支付方式,0: 未支付;1: 支付宝,;2: 微信
        }

        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    def pay_success(self, order_id):    #支付成功回调接口
        method = 'post'
        url = self.url + '/order/paySuccess'
        payload = {"orderId": order_id,"payType":2}
        return SendMethod.send_method(method=method, url=url, data=payload, headers=self.headers)


if __name__ == '__main__':
    url = "http://47.108.206.100:8085"
    payload = {
        "username": "Jerry5",
        "password": "123456789"}
    headers = Memberlnterface(url).get_member_token(payload)
    order = OrderInterface(url, headers)
    # print(order.confirm_order(2680))  # 调用确认订单接口
    # print(order.generate_order(2680, 2464))  # 调用生成订单接口
    print(order.pay_success(3464))  # 调用支付成功回调接口
